package com.example.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;

import com.example.feignService.FeignEurekaClient;

/**
 * 客户端请求负载均衡<br>
 * 请求不带端口号，Ribbon和Feign会随机请求client或client2项目
 * 
 * @author Feny
 * @email 1220301855@qq.com
 * @version 1.0
 * @date 2018年11月19日下午4:57:58
 */
@RestController
public class IndexController {

	@Autowired
	private RestTemplate restTemplate;

	@Autowired
	private FeignEurekaClient client;

	@RequestMapping("/callHelloForRibbon")
	public String callHelloForRibbon() {
		// 在restTemplate上加 @LoadBalanced 实现
		return restTemplate.getForObject("http://EUREKA-CLIENT/hello", String.class);
	}

	@RequestMapping("/callHelloForFeign")
	public String callHelloForFeign() {
		// 在启动类上加@EnableFeignClients
		return client.helloService();
	}
}
